package com.lijie.springcloud.controller;


import com.lijie.springcloud.entries.Payment;
import com.lijie.springcloud.entries.Result;
import com.lijie.springcloud.serivce.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;

/**
 * @Authorr 李杰
 * @Date：2022/1/3112:06
 **/
@RestController
@Slf4j
@RequestMapping("/provider/payment")
public class PaymentController {
    @Resource
    PaymentService paymentService;

    @PostMapping("/create")
    public Result<Payment> create(@RequestBody Payment payment){
        Result<Payment> instanceSuccess= null;
        try {
//            log.info("11");
            System.out.println(111);
            System.out.println(1);
            System.out.println(1);
            boolean save = paymentService.save(payment);
            instanceSuccess = new Result<>();
            if(!save){
                instanceSuccess.setErrored("新增失败");
            }else{
                instanceSuccess.setSuccess("新增成功");
            }
        } catch (Exception e) {
            instanceSuccess.setMessage(e.getMessage());
        }
        return instanceSuccess;
    }
    @GetMapping("/getById/{id}")
    public Result<Payment> selectById(@PathVariable Integer id){
        Result<Payment> result= null;
        try {
            Payment byId = paymentService.getById(id);
            result=new Result<>();
            result.setSuccess();
            if(null!=byId){
                result.setData(byId);
                result.setMessage("123");
            }else{
                result.setErrored("没有id为"+id+"的数据");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(result.getData());
        return result;
    }

}
